//
// Created by 17775 on 2024/11/21.
//

#ifndef RAYCI_BEAM_QUALITY_VIEW_H
#define RAYCI_BEAM_QUALITY_VIEW_H

#include <QDockWidget>
#include "../Common/common_2dview.h"
#include "../Common/commonchart.h"
#include "../Common/common_chart_options.h"
#include "../RayCi/Beam_Quality.h"
#include"Beam_Quality_Result.h"
#include <QtDataVisualization>
#include "ThreeDBeamQuality.h"
#include "../common/commonlutwidget.h"


QT_BEGIN_NAMESPACE
namespace Ui { class Beam_Quality_View; }
QT_END_NAMESPACE

class Beam_Quality_View : public QDockWidget {
Q_OBJECT
    signals:
    void sendAutoContrast(bool isAuto);
    void stopBeamQualityThread();
    void reportBeamQuality();
    void showBeamQuality2DView();
    void AdjustAoiToCenter();
    void BeamQualityClicked();
    void saveBeamQualityResult();

public slots:
    void setAutoContrast();


public:
    explicit Beam_Quality_View(QWidget *parent = nullptr);
    ~Beam_Quality_View() override;
    void setWindowTitleName(const QString& name);
    ThreeDBeamQuality* threeDBeamQuality = nullptr;

    void setAuto(bool bAuto);
    void saveBeamQuality();
    void refreshChart();
    Common_2DView* getComm2DView() {
        return common2DView;
    }
    ThreeDBeamQuality* get3DView() {
        return threeDBeamQuality;
    }

    Beam_Quality_Result *getBeamQualityResultView() {
        return beamQualityResult;
    }
    void clear();


    QList<CommonChart*> charts = {
        new CommonChart(this),  // FitViewChart->Diameter
        new CommonChart(this),  // FitViewChart->Ellipticity
        new CommonChart(this),  // FitViewChart->Eccentricity
        new CommonChart(this),  // FitViewChart->AzimuthAngle
        // new CommonChart(this),  // FitViewChart->3DView
    };


    QList<Common_Chart_Options*> options = {
        new Common_Chart_Options(this->parentWidget()),  // FitViewChart->DiameterOptions
        new Common_Chart_Options(this->parentWidget()),  // FitViewChart->EllipticityOptions
        new Common_Chart_Options(this->parentWidget()),  // FitViewChart->EccentricityOptions
        new Common_Chart_Options(this->parentWidget()),  // FitViewChart->AzimuthAngleOptions
       // new Common_Chart_Options(this->parentWidget()),  // FitViewChart->3DOptions

};
     void clearChart();
     void updateResult(bool alluodate,const BeamQualityResult& result);
     // void HideEllipticity();
     // void HideEccentricity();
     // void HideAzimuthAngle();
     void showISO_1();
     void showISO_2();
     void showDetails();
     void UpdateBeamQualityIndex(int currentindex,int totalindex);
private:
    Ui::Beam_Quality_View *ui;
    QWidget* menuPanel = nullptr;
    QWidget* lutPanel = nullptr;
    QVBoxLayout* menuLayout = nullptr;
    QVBoxLayout* lutLayout = nullptr;
    QWidget* centralWidget = nullptr;
    QHBoxLayout* mainLayout = nullptr;
    Common_2DView* common2DView = nullptr;

    QPushButton* btnSave = nullptr;
    QPushButton* btnGenerateSingle = nullptr;
    QPushButton* btn2DView = nullptr;
    QPushButton* btnDiameter = nullptr;
    QPushButton* btnQualityResults = nullptr;
    QPushButton* btn3DView = nullptr;
    QPushButton* btnEllipticityPreview = nullptr;
    QPushButton* btnEccentricityPreview = nullptr;
    QPushButton* btnAzimuthAnglePreview = nullptr;
    QPushButton* btnSelect = nullptr;
    QPushButton* btnReport = nullptr;
    QPushButton* btnAdjustAOItocenter =nullptr;
    QHBoxLayout *navLayout = nullptr;
    QPushButton *btnFirst = nullptr;
    QPushButton *btnPrev = nullptr;
    QLabel *pageLabel = nullptr;
    QPushButton *btnNext = nullptr;
    QPushButton *btnLast =nullptr;

    QCheckBox* cBox_Auto = nullptr;
    QWidget* LUT_Widget = nullptr;
    CommonLutWidget* m_lutWidget = nullptr;
    QSplitter* mainSplitter = nullptr;
    QSplitter* topSplitter = nullptr;
    QSplitter* topleftSplitter = nullptr;
    QSplitter* toprightSplitter = nullptr;
    QSplitter* bottomSplitter = nullptr;

    Beam_Quality_Result* beamQualityResult = nullptr;
    Beam_Quality_Result* beamQualityResult1 = nullptr;


    bool _2DViewIsShow = true;
    bool DiameterIsShow = true;
    bool QualityResultIsShow = true;
    bool _3DIsShow = true;
    bool EllipticityIsHide = false;
    bool EccentricityIsHide = false;
    bool AzimuthAngleIsHide = false;
    void show2DView();
    void showDiameterView();
    void show3DView();
    void showQualityResultView();
    void hideEllipticityy();
    void hideEccentricity();
    void hideAzimuthAngle();



    void closeEvent(QCloseEvent *event) override;

void mousePressEvent(QMouseEvent *event);

void resizeEvent(QResizeEvent *event);
};


#endif //RAYCI_BEAM_QUALITY_VIEW_H
